PHP

How to print the class name using magic constant __CLASS__ in PHP | PHP programs

How to print the class name using magic constant __CLASS__ in PHP | PHP programs

How to print the class name using magic constant __CLASS__ in PHP | PHP programs

We will print the name of the class using the magic constant __CLASS__. The __CLASS__ constant returns a case-sensitive class name.

<?php

    class Sample
    {
        public function MyFunction()
        {
            print("Class Name: ".__CLASS__."<br>");
        }
    }
    
    $S=new Sample();
    $S->MyFunction();
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community